home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 10 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.8 KB

  1. Path: chronicle.mti.sgi.com!news
  2. From: clamage@Eng.Sun.COM (Steve Clamage)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: RTTI implementation...
  5. Date: 05 Jan 1996 21:20:04 GMT
  6. Organization: Sun Microsystems Inc.
  7. Approved: austern@mti.sgi.com
  8. Message-ID: <4ck3cv$qts@engnews1.Eng.Sun.COM>
  9. References: <4ciauq$2e1@trojan.neta.com>
  10. Reply-To: clamage@Eng.Sun.COM
  11. NNTP-Posting-Host: isolde.mti.sgi.com
  12.  
  13.  
  14. In article 2e1@trojan.neta.com, jonnyg@trojan.neta.com (J. Greenblatt) writes:
  15.  
  16. >Problem:
  17.  
  18. >    It seems that RTTI requires a compile time flag to be activated. When
  19. >activated the code seems to bloat whether you actualy use the feature in the
  20. >specific peice of code or not. From what I have learned this overhead is due
  21. >to extra work done when the object is constructed (A pointer to this with a
  22. >string representation of the class is added to a table).
  23.  
  24. That sounds like not a very efficient way to implement RTTI. I would
  25. expect all RTTI extensions to consist only of static data, with a pointer
  26. to such static data in the vtable for a type. Vtables are also normally
  27. static data. (Types with no virtual functions don't have RTTI available
  28. anyway, except for built-in types.) The only RTTI overhead is the extra
  29. static data tables, one table per RTTI type. Objects should have no space
  30. or time overhead whatever associated with RTTI. (We are talking about
  31. implementation details here, not language definition. Certainly RTTI
  32. implementations exist that work the way I have described.)
  33.  
  34. >Proposed solution:
  35.  
  36. >    Allow RTTI to be implemented on the whole system as it is now and keep
  37. >it as a option. In addition allow RTTI to be turned on on a class by class 
  38. >basis. On a class by class basis RTTI would be enabled if a base of the 
  39. >current class is declared with the RTTI keyword. The extra RTTI keywords 
  40. >(dynamic_cast, static_cast, etc...) are only defined for classes declared 
  41. >as RTTI classes. The RTTI overhead is now only felt when accessing objects
  42. >of RTTI classes.
  43.  
  44. But every class would have to be declared to be RTTI or they wouldn't
  45. be very useful. A major purpose of classes is to serve as a base for
  46. further development. If you create a FOO class and put it in library,
  47. no client of the class could use RTTI on derived classs unless you
  48. make FOO an RTTI class.
  49.  
  50. A C++ implementor might choose to have a compiler flag that eliminated
  51. the RTTI data to reduce static data space in programs that don't want
  52. to use RTTI, just as some compilers have a flag that turns off exception
  53. code. That isn't, and IMHO should not be, part of the language definition.
  54. Compilers operating in a no-exception or no-RTTI mode are not truly C++
  55. compilers. The ability to disable such language features is there for those
  56. with severe space constraints.
  57.  
  58. ---
  59. Steve Clamage, stephen.clamage@eng.sun.com
  60.  
  61.  
  62.  
  63. -- 
  64. Matt Austern
  65. SGI: MTI Compilers Group
  66. austern@isolde.mti.sgi.com
  67.